package com.example.highclasscomponent.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.example.highclasscomponent.DynamicFragment;
import com.example.highclasscomponent.pojo.GoodsInfo;

import java.util.List;

public class MobilePageAdapter extends FragmentPagerAdapter {

    private final List<GoodsInfo> mGoodsList;

    public MobilePageAdapter(@NonNull FragmentManager fm, List<GoodsInfo> goodsList) {
        //会将当前fragment设置为Resume的状态，将上一个fragment设置为start状态
        //，所以，你可以在onResume方法加载数据
        super(fm,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) ;
        this.mGoodsList=goodsList;

    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        GoodsInfo info=mGoodsList.get(position);
        return DynamicFragment.newInstance(position,info.pic,info.description);
    }

    @Override
    public int getCount() {
        return mGoodsList.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return mGoodsList.get(position).name;
    }
}
